package com.xuelang.pipeline.entry.pipeline;

import com.xuelang.pipeline.app.pipeline.DeploymentUnitService;
import com.xuelang.pipeline.client.common.constant.DictDTO;
import com.xuelang.pipeline.client.common.request.PageParam;
import com.xuelang.pipeline.client.common.result.ApiResult;
import com.xuelang.pipeline.client.common.result.PageRecord;
import com.xuelang.pipeline.client.pipeline.IDeploymentUnitService;
import com.xuelang.pipeline.client.pipeline.dto.DeploymentUnitDTO;
import com.xuelang.pipeline.client.pipeline.dto.DeploymentUnitQuery;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 部署单控制类
 *
 * @author : yixin.lys
 * @date : 2024-06-26 11:41
 **/
@Slf4j
@RestController
@RequestMapping("/deploymentUnit")
public class DeploymentUnitController implements IDeploymentUnitService {

    @Autowired
    private DeploymentUnitService deploymentUnitService;

    @Override
    public ApiResult<PageRecord<DeploymentUnitDTO>> page(PageParam<DeploymentUnitQuery> query) {
        return ApiResult.success(deploymentUnitService.page(query));
    }

    @Override
    public ApiResult<DeploymentUnitDTO> queryByPipelineInstanceCode(String pipelineInstanceCode) {
        return ApiResult.success(deploymentUnitService.queryByPipelineInstanceCode(pipelineInstanceCode));
    }

    @Override
    public ApiResult<Boolean> rollback(String id) {
        return ApiResult.success(deploymentUnitService.rollback(id));
    }

    @Override
    public ApiResult<Boolean> continueDeployment(String id) {
        return ApiResult.success(deploymentUnitService.continueDeployment(id));
    }

    @Override
    public ApiResult<List<DictDTO>> deploymentProcessStatus() {
        return ApiResult.success(deploymentUnitService.deploymentProcessStatus());
    }
}
